/**
 * Created by win10 on 2017/11/22.
 */
import axios from 'axios'
// import router from '../router/index'

//
axios.defaults.timeout = 20000
axios.defaults.headers.post['Content-Type'] = 'application/json'
axios.defaults.withCredentials = true // 默认携带cookie
// axios.defaults.baseURL = 'http://192.168.3.145:8000'
const instance = axios.create({
  // baseURL: 'http://172.20.10.4:8080',
  // baseURL: 'http://taifuli.jiucaixueyuan.com:8080',
  // headers: {
  //   'Content-Type': 'application/json'
  // },
  // withCredentials: true
})

// 添加请求拦截器，并赋予全局axios
axios.interceptors.request.use = instance.interceptors.request.use
instance.interceptors.request.use(config => {
  // 在发送请求前做点什么
  // if (config.method === 'get' || config.method === 'GET') {
  //   config.data = true
  // }
  // config.headers['H-TOKEN'] = '111'
  // config.url = '/rpm-app-service' + config.url
  // config.url = '.' + config.url
  config.url = '/api' + config.url // build时把这句代码注掉
  return config
}, err => {
  // 对请求错误做点什么
  return Promise.reject(err)
})
// axios添加响应拦截器
instance.interceptors.response.use(response => {
  // 对响应数据做点什么
  return response
}, err => {
  // 对响应错误做点什么

  return Promise.reject(err)
})
// store.commit(types.LOGOUT);
// router.replace({
//   path: 'login',
//   query: {redirect: router.currentRoute.fullPath}
// })
// export default axios
export default instance
